<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>《在Flutter中构建笑话生成器应用程序》 - Lucklyの博客 - 在阅读中遇见自己</title><meta name="Description" content="早起的年轻人做的网站"><meta property="og:title" content="《在Flutter中构建笑话生成器应用程序》" />
<meta property="og:description" content="
在本教程中，我将向您展示如何使用 Flutter 制作一个简单的笑话生成器应用程序
" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" />
<meta property="og:image" content="https://luckly.work/logo.png"/>
<meta property="article:published_time" content="2021-07-26T23:09:06+08:00" />
<meta property="article:modified_time" content="2021-07-26T23:09:06+08:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://luckly.work/logo.png"/>

<meta name="twitter:title" content="《在Flutter中构建笑话生成器应用程序》"/>
<meta name="twitter:description" content="
在本教程中，我将向您展示如何使用 Flutter 制作一个简单的笑话生成器应用程序
"/>
<meta name="application-name" content="LoveIt">
<meta name="apple-mobile-web-app-title" content="LoveIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" /><link rel="prev" href="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E7%9A%84%E5%A4%9A%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/" /><link rel="next" href="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BAsuingapp/" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.7.2/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "《在Flutter中构建笑话生成器应用程序》",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/luckly.work\/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F\/"
        },"image": [{
                            "@type": "ImageObject",
                            "url": "https:\/\/luckly.work\/images\/Apple-Devices-Preview.png",
                            "width":  3200 ,
                            "height":  2048 
                        }],"genre": "posts","wordcount":  525 ,
        "url": "https:\/\/luckly.work\/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F\/","datePublished": "2021-07-26T23:09:06+08:00","dateModified": "2021-07-26T23:09:06+08:00","license": "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.","publisher": {
            "@type": "Organization",
            "name": "xxxx","logo": {
                    "@type": "ImageObject",
                    "url": "https:\/\/luckly.work\/images\/avatar.png",
                    "width":  528 ,
                    "height":  560 
                }},"author": {
                "@type": "Person",
                "name": "早起的年轻人"
            },"description": ""
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="Lucklyの博客 - 在阅读中遇见自己"><span class="header-title-pre"><i class='far fa-kiss-wink-heart fa-fw'></i></span><span id="id-1" class="typeit"></span></a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 所有文章 </a><a class="menu-item" href="/categories/flutter/"> Flutter </a><a class="menu-item" href="/categories/read/"> 读书笔记 </a><a class="menu-item" href="/categories/go/"> Go </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="/about/"> 关于 </a><a class="menu-item" href="https://github.com/ITmxs" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw'></i> Github </a><a class="menu-item" href="/friend/"><i class='fas fa-user-friends'></i> 友链 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="Lucklyの博客 - 在阅读中遇见自己"><span class="header-title-pre"><i class='far fa-kiss-wink-heart fa-fw'></i></span><span id="id-2" class="typeit"></span></a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">所有文章</a><a class="menu-item" href="/categories/flutter/" title="">Flutter</a><a class="menu-item" href="/categories/read/" title="">读书笔记</a><a class="menu-item" href="/categories/go/" title="">Go</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="/about/" title="">关于</a><a class="menu-item" href="https://github.com/ITmxs" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw'></i>Github</a><a class="menu-item" href="/friend/" title=""><i class='fas fa-user-friends'></i>友链</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">《在Flutter中构建笑话生成器应用程序》</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>早起的年轻人</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2021-07-26">2021-07-26</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 525 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 2 分钟&nbsp;</div>
        </div><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png"
        data-srcset="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png, https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png 1.5x, https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png 2x"
        data-sizes="auto"
        alt="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png"
        title="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png" /></div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents"></nav></div>
            </div><div class="content" id="content"><blockquote>
<p>在本教程中，我将向您展示如何使用 Flutter 制作一个简单的笑话生成器应用程序</p>
</blockquote>
<p>对于这个项目，我们将从 RESTful API 获取数据</p>
<p>API的链接： <a href="https://official-joke-api.appspot.com/jokes/programming/random" target="_blank" rel="noopener noreffer">随机笑话</a></p>
<p>对于这个项目，我不会关注应用程序的 UI，我们只会关注如何从 URL 中获取数据，以及如何显示它们</p>
<p>在我们开始之前，您必须将此包添加到您的 pubspec.yaml 文件中</p>
<p>依赖项：http：^0.12.2</p>
<p>有关 HTTP 包的更多信息，请访问：<a href="https://pub.dev/packages/http" target="_blank" rel="noopener noreffer">HTTP 包 Flutter</a></p>
<p>源代码：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">  1
</span><span class="lnt">  2
</span><span class="lnt">  3
</span><span class="lnt">  4
</span><span class="lnt">  5
</span><span class="lnt">  6
</span><span class="lnt">  7
</span><span class="lnt">  8
</span><span class="lnt">  9
</span><span class="lnt"> 10
</span><span class="lnt"> 11
</span><span class="lnt"> 12
</span><span class="lnt"> 13
</span><span class="lnt"> 14
</span><span class="lnt"> 15
</span><span class="lnt"> 16
</span><span class="lnt"> 17
</span><span class="lnt"> 18
</span><span class="lnt"> 19
</span><span class="lnt"> 20
</span><span class="lnt"> 21
</span><span class="lnt"> 22
</span><span class="lnt"> 23
</span><span class="lnt"> 24
</span><span class="lnt"> 25
</span><span class="lnt"> 26
</span><span class="lnt"> 27
</span><span class="lnt"> 28
</span><span class="lnt"> 29
</span><span class="lnt"> 30
</span><span class="lnt"> 31
</span><span class="lnt"> 32
</span><span class="lnt"> 33
</span><span class="lnt"> 34
</span><span class="lnt"> 35
</span><span class="lnt"> 36
</span><span class="lnt"> 37
</span><span class="lnt"> 38
</span><span class="lnt"> 39
</span><span class="lnt"> 40
</span><span class="lnt"> 41
</span><span class="lnt"> 42
</span><span class="lnt"> 43
</span><span class="lnt"> 44
</span><span class="lnt"> 45
</span><span class="lnt"> 46
</span><span class="lnt"> 47
</span><span class="lnt"> 48
</span><span class="lnt"> 49
</span><span class="lnt"> 50
</span><span class="lnt"> 51
</span><span class="lnt"> 52
</span><span class="lnt"> 53
</span><span class="lnt"> 54
</span><span class="lnt"> 55
</span><span class="lnt"> 56
</span><span class="lnt"> 57
</span><span class="lnt"> 58
</span><span class="lnt"> 59
</span><span class="lnt"> 60
</span><span class="lnt"> 61
</span><span class="lnt"> 62
</span><span class="lnt"> 63
</span><span class="lnt"> 64
</span><span class="lnt"> 65
</span><span class="lnt"> 66
</span><span class="lnt"> 67
</span><span class="lnt"> 68
</span><span class="lnt"> 69
</span><span class="lnt"> 70
</span><span class="lnt"> 71
</span><span class="lnt"> 72
</span><span class="lnt"> 73
</span><span class="lnt"> 74
</span><span class="lnt"> 75
</span><span class="lnt"> 76
</span><span class="lnt"> 77
</span><span class="lnt"> 78
</span><span class="lnt"> 79
</span><span class="lnt"> 80
</span><span class="lnt"> 81
</span><span class="lnt"> 82
</span><span class="lnt"> 83
</span><span class="lnt"> 84
</span><span class="lnt"> 85
</span><span class="lnt"> 86
</span><span class="lnt"> 87
</span><span class="lnt"> 88
</span><span class="lnt"> 89
</span><span class="lnt"> 90
</span><span class="lnt"> 91
</span><span class="lnt"> 92
</span><span class="lnt"> 93
</span><span class="lnt"> 94
</span><span class="lnt"> 95
</span><span class="lnt"> 96
</span><span class="lnt"> 97
</span><span class="lnt"> 98
</span><span class="lnt"> 99
</span><span class="lnt">100
</span><span class="lnt">101
</span><span class="lnt">102
</span><span class="lnt">103
</span><span class="lnt">104
</span><span class="lnt">105
</span><span class="lnt">106
</span><span class="lnt">107
</span><span class="lnt">108
</span><span class="lnt">109
</span><span class="lnt">110
</span><span class="lnt">111
</span><span class="lnt">112
</span><span class="lnt">113
</span><span class="lnt">114
</span><span class="lnt">115
</span><span class="lnt">116
</span><span class="lnt">117
</span><span class="lnt">118
</span><span class="lnt">119
</span><span class="lnt">120
</span><span class="lnt">121
</span><span class="lnt">122
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-dart" data-lang="dart"><span class="k">import</span> <span class="s1">&#39;dart:convert&#39;</span><span class="p">;</span>

<span class="k">import</span> <span class="s1">&#39;package:flutter/material.dart&#39;</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">&#39;package:http/http.dart&#39;</span><span class="p">;</span>

<span class="kt">void</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="n">runApp</span><span class="p">(</span><span class="n">MyApp</span><span class="p">());</span>
<span class="p">}</span>

<span class="kd">class</span> <span class="nc">MyApp</span> <span class="kd">extends</span> <span class="n">StatelessWidget</span> <span class="p">{</span>
  <span class="c1">// This widget is the root of your application.
</span><span class="c1"></span>  <span class="err">@</span><span class="n">override</span>
  <span class="n">Widget</span> <span class="n">build</span><span class="p">(</span><span class="n">BuildContext</span> <span class="n">context</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="n">MaterialApp</span><span class="p">(</span>
      <span class="nl">debugShowCheckedModeBanner:</span> <span class="kc">false</span><span class="p">,</span>
      <span class="nl">home:</span> <span class="n">JokeApp</span><span class="p">(),</span>
    <span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span>

<span class="kd">class</span> <span class="nc">JokeApp</span> <span class="kd">extends</span> <span class="n">StatefulWidget</span> <span class="p">{</span>
  <span class="err">@</span><span class="n">override</span>
  <span class="n">_JokeAppState</span> <span class="n">createState</span><span class="p">()</span> <span class="o">=&gt;</span> <span class="n">_JokeAppState</span><span class="p">();</span>
<span class="p">}</span>

<span class="kd">class</span> <span class="nc">_JokeAppState</span> <span class="kd">extends</span> <span class="n">State</span><span class="o">&lt;</span><span class="n">JokeApp</span><span class="o">&gt;</span> <span class="p">{</span>
  <span class="c1">//performing the http request
</span><span class="c1"></span>  <span class="kt">String</span> <span class="n">url</span> <span class="o">=</span> <span class="s2">&#34;https://official-joke-api.appspot.com/jokes/programming/random&#34;</span><span class="p">;</span>
  <span class="kt">String</span> <span class="n">setup</span> <span class="o">=</span> <span class="s2">&#34;&#34;</span><span class="p">;</span>
  <span class="kt">String</span> <span class="n">punchline</span> <span class="o">=</span> <span class="s2">&#34;&#34;</span><span class="p">;</span>
  <span class="kt">String</span> <span class="n">type</span> <span class="o">=</span> <span class="s2">&#34;&#34;</span><span class="p">;</span>
  <span class="n">Future</span><span class="o">&lt;</span><span class="kt">String</span><span class="o">&gt;</span> <span class="n">getData</span><span class="p">()</span> <span class="kd">async</span> <span class="p">{</span>
    <span class="n">Response</span> <span class="n">res</span> <span class="o">=</span> <span class="kd">await</span> <span class="kd">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="nl">headers:</span> <span class="p">{</span><span class="s2">&#34;Accept&#34;</span><span class="o">:</span> <span class="s2">&#34;application/json&#34;</span><span class="p">});</span>
    <span class="kd">var</span> <span class="n">data</span> <span class="o">=</span> <span class="n">jsonDecode</span><span class="p">(</span><span class="n">res</span><span class="p">.</span><span class="n">body</span><span class="p">);</span>
    <span class="n">print</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="m">0</span><span class="p">][</span><span class="s1">&#39;setup&#39;</span><span class="p">]);</span>
    <span class="n">print</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="m">0</span><span class="p">][</span><span class="s1">&#39;punchline&#39;</span><span class="p">]);</span>
    <span class="n">setState</span><span class="p">(()</span> <span class="p">{</span>
      <span class="n">setup</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="m">0</span><span class="p">][</span><span class="s1">&#39;setup&#39;</span><span class="p">];</span>
      <span class="n">punchline</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="m">0</span><span class="p">][</span><span class="s1">&#39;punchline&#39;</span><span class="p">];</span>
      <span class="n">type</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="m">0</span><span class="p">][</span><span class="s1">&#39;type&#39;</span><span class="p">];</span>
    <span class="p">});</span>
    <span class="n">print</span><span class="p">(</span><span class="n">res</span><span class="p">.</span><span class="n">body</span><span class="p">);</span>
  <span class="p">}</span>

  <span class="err">@</span><span class="n">override</span>
  <span class="kt">void</span> <span class="n">initState</span><span class="p">()</span> <span class="p">{</span>
    <span class="c1">// TODO: implement initState
</span><span class="c1"></span>    <span class="n">getData</span><span class="p">();</span>
    <span class="k">super</span><span class="p">.</span><span class="n">initState</span><span class="p">();</span>
  <span class="p">}</span>

  <span class="err">@</span><span class="n">override</span>
  <span class="n">Widget</span> <span class="n">build</span><span class="p">(</span><span class="n">BuildContext</span> <span class="n">context</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="n">Scaffold</span><span class="p">(</span>
      <span class="nl">backgroundColor:</span> <span class="n">Color</span><span class="p">(</span><span class="mh">0xFF212121</span><span class="p">),</span>
      <span class="nl">body:</span> <span class="n">Container</span><span class="p">(</span>
        <span class="nl">width:</span> <span class="kt">double</span><span class="p">.</span><span class="n">infinity</span><span class="p">,</span>
        <span class="nl">child:</span> <span class="n">Column</span><span class="p">(</span>
          <span class="nl">mainAxisAlignment:</span> <span class="n">MainAxisAlignment</span><span class="p">.</span><span class="n">center</span><span class="p">,</span>
          <span class="nl">crossAxisAlignment:</span> <span class="n">CrossAxisAlignment</span><span class="p">.</span><span class="n">center</span><span class="p">,</span>
          <span class="nl">children:</span> <span class="p">[</span>
            <span class="n">Text</span><span class="p">(</span>
              <span class="s2">&#34;</span><span class="si">${</span><span class="n">type</span><span class="si">}</span><span class="s2"> Jokes&#34;</span><span class="p">,</span>
              <span class="nl">style:</span> <span class="n">TextStyle</span><span class="p">(</span>
                <span class="nl">color:</span> <span class="n">Colors</span><span class="p">.</span><span class="n">white</span><span class="p">,</span>
                <span class="nl">fontSize:</span> <span class="m">26.0</span><span class="p">,</span>
              <span class="p">),</span>
            <span class="p">),</span>
            <span class="n">SizedBox</span><span class="p">(</span>
              <span class="nl">height:</span> <span class="m">30.0</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="n">Card</span><span class="p">(</span>
              <span class="nl">child:</span> <span class="n">Container</span><span class="p">(</span>
                <span class="nl">width:</span> <span class="n">MediaQuery</span><span class="p">.</span><span class="n">of</span><span class="p">(</span><span class="n">context</span><span class="p">).</span><span class="n">size</span><span class="p">.</span><span class="n">width</span> <span class="o">*</span> <span class="m">0.85</span><span class="p">,</span>
                <span class="nl">height:</span> <span class="n">MediaQuery</span><span class="p">.</span><span class="n">of</span><span class="p">(</span><span class="n">context</span><span class="p">).</span><span class="n">size</span><span class="p">.</span><span class="n">height</span> <span class="o">*</span> <span class="m">0.6</span><span class="p">,</span>
                <span class="nl">child:</span> <span class="n">Padding</span><span class="p">(</span>
                  <span class="nl">padding:</span> <span class="kd">const</span> <span class="n">EdgeInsets</span><span class="p">.</span><span class="n">all</span><span class="p">(</span><span class="m">12.0</span><span class="p">),</span>
                  <span class="nl">child:</span> <span class="n">Column</span><span class="p">(</span>
                    <span class="nl">mainAxisAlignment:</span> <span class="n">MainAxisAlignment</span><span class="p">.</span><span class="n">center</span><span class="p">,</span>
                    <span class="nl">crossAxisAlignment:</span> <span class="n">CrossAxisAlignment</span><span class="p">.</span><span class="n">center</span><span class="p">,</span>
                    <span class="nl">children:</span> <span class="p">[</span>
                      <span class="n">Text</span><span class="p">(</span>
                        <span class="s2">&#34;- </span><span class="si">${</span><span class="n">setup</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">,</span>
                        <span class="nl">style:</span> <span class="n">TextStyle</span><span class="p">(</span>
                          <span class="nl">fontSize:</span> <span class="m">26.0</span><span class="p">,</span>
                        <span class="p">),</span>
                      <span class="p">),</span>
                      <span class="n">SizedBox</span><span class="p">(</span>
                        <span class="nl">height:</span> <span class="m">10.0</span><span class="p">,</span>
                      <span class="p">),</span>
                      <span class="n">Text</span><span class="p">(</span>
                        <span class="s2">&#34;- </span><span class="si">${</span><span class="n">punchline</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">,</span>
                        <span class="nl">style:</span> <span class="n">TextStyle</span><span class="p">(</span>
                          <span class="nl">fontSize:</span> <span class="m">26.0</span><span class="p">,</span>
                        <span class="p">),</span>
                      <span class="p">),</span>
                    <span class="p">],</span>
                  <span class="p">),</span>
                <span class="p">),</span>
              <span class="p">),</span>
            <span class="p">),</span>
            <span class="n">SizedBox</span><span class="p">(</span>
              <span class="nl">height:</span> <span class="m">20.0</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="n">RaisedButton</span><span class="p">(</span>
              <span class="nl">onPressed:</span> <span class="p">()</span> <span class="p">{</span>
                <span class="n">getData</span><span class="p">();</span>
              <span class="p">},</span>
              <span class="nl">color:</span> <span class="n">Color</span><span class="p">(</span><span class="mh">0xFFFAFAFA</span><span class="p">),</span>
              <span class="nl">child:</span> <span class="n">Padding</span><span class="p">(</span>
                <span class="nl">padding:</span>
                    <span class="kd">const</span> <span class="n">EdgeInsets</span><span class="p">.</span><span class="n">symmetric</span><span class="p">(</span><span class="nl">horizontal:</span> <span class="m">15.0</span><span class="p">,</span> <span class="nl">vertical:</span> <span class="m">8.0</span><span class="p">),</span>
                <span class="nl">child:</span> <span class="n">Text</span><span class="p">(</span><span class="s2">&#34;Another Joke&#34;</span><span class="p">),</span>
              <span class="p">),</span>
            <span class="p">)</span>
          <span class="p">],</span>
        <span class="p">),</span>
      <span class="p">),</span>
    <span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span>

</code></pre></td></tr></table>
</div>
</div></div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2021-07-26</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中构建笑话生成器应用程序》"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Hacker News" data-sharer="hackernews" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中构建笑话生成器应用程序》"><i class="fab fa-hacker-news fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中构建笑话生成器应用程序》"><i data-svg-src="https://cdn.jsdelivr.net/npm/simple-icons@2.14.0/icons/line.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BA%E7%AC%91%E8%AF%9D%E7%94%9F%E6%88%90%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中构建笑话生成器应用程序》" data-image="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png"><i class="fab fa-weibo fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/%E5%9C%A8flutter%E4%B8%AD%E7%9A%84%E5%A4%9A%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/" class="prev" rel="prev" title="《在Flutter中的多版本控制》"><i class="fas fa-angle-left fa-fw"></i>《在Flutter中的多版本控制》</a>
            <a href="/%E5%9C%A8flutter%E4%B8%AD%E6%9E%84%E5%BB%BAsuingapp/" class="next" rel="next" title="《在Flutter中构建suingAPP》">《在Flutter中构建suingAPP》<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.79.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">早起的年轻人</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cookieconsent@3.1.1/build/cookieconsent.min.css"><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/smooth-scroll@16.1.3/dist/smooth-scroll.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/autocomplete.js@0.37.1/dist/autocomplete.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/algoliasearch@4.2.0/dist/algoliasearch-lite.umd.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lazysizes@5.2.2/lazysizes.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sharer.js@0.4.0/sharer.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/typeit@7.0.4/dist/typeit.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/cookieconsent@3.1.1/build/cookieconsent.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{},"cookieconsent":{"content":{"dismiss":"同意","link":"了解更多","message":"本网站使用 Cookies 来改善您的浏览体验."},"enable":true,"palette":{"button":{"background":"#f0f0f0"},"popup":{"background":"#1aa3ff"}},"theme":"edgeless"},"data":{"id-1":"早起的年轻人","id-2":"早起的年轻人"},"search":{"algoliaAppID":"PASDMWALPK","algoliaIndex":"index.zh-cn","algoliaSearchKey":"b42948e51daaa93df92381c8e2ac0f93","highlightTag":"em","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"algolia"},"typeit":{"cursorChar":"|","cursorSpeed":1000,"data":{"id-1":["id-1"],"id-2":["id-2"]},"duration":-1,"speed":100}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
